From 3f49c79d0760bceaff73e0a97ee537ae810f00ca Mon Sep 17 00:00:00 2001 From: gentoo90 Date: Sun, 26 Jul 2015 14:21:44 +0300 Subject: [PATCH] Bashcomp: improve performance Calling `cargo --list` on every completion is too slow. Call it once on bash start and cache the output. --- src/etc/cargo.bashcomp.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/etc/cargo.bashcomp.sh b/src/etc/cargo.bashcomp.sh index d3a1649a8..968601365 100644 --- a/src/etc/cargo.bashcomp.sh +++ b/src/etc/cargo.bashcomp.sh @@ -8,7 +8,6 @@ _cargo() cmd=${words[1]} - local commands=$(cargo --list | tail -n +2) local vcs='git hg none' local opt_help='-h --help' @@ -49,7 +48,7 @@ _cargo() if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W "${opt___nocmd}" -- "$cur" ) ) else - COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) ) fi elif [[ $cword -ge 2 ]]; then case "${prev}" in @@ -63,7 +62,7 @@ _cargo() COMPREPLY=( $( compgen -W "$(_get_examples)" -- "$cur" ) ) ;; help) - COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "$__cargo_commands" -- "$cur" ) ) ;; *) local opt_var=opt__${cmd//-/_} @@ -78,6 +77,8 @@ _cargo() } && complete -F _cargo cargo +__cargo_commands=$(cargo --list | tail -n +2) + _locate_manifest(){ local manifest=`cargo locate-project 2>/dev/null` # regexp-replace manifest '\{"root":"|"\}' '' -- 2.30.2